#!/usr/bin/python
# -*- coding: UTF-8 -*-
from selenium import webdriver;
from selenium.common.exceptions import TimeoutException
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import json
browser=webdriver.Chrome()
# browser.set_window_size(1400,900)
wait=WebDriverWait(browser, 10);




def getCookies():
    url="https://passport.weibo.cn/signin/login"
    browser.get(url)
    time.sleep(2)
    user_name = wait.until(
        EC.presence_of_element_located((By.CSS_SELECTOR, "#loginName"))
    )
    user_name.send_keys("13242408610")
    password = wait.until(
        EC.presence_of_element_located((By.CSS_SELECTOR, "#loginPassword"))
    )
    password.send_keys("441432")
    login= wait.until(
        EC.presence_of_element_located((By.CSS_SELECTOR, "#loginAction"))
    )


    login.click()
    time.sleep(5)
    browser.get("https://weibo.cn/search/mblog?keyword=小猪佩奇&mp=100&page=1")

    results=browser.get_cookies();
    cookie={}
    for res in results:
        cookie[res.get("name")]=res.get("value")
    print(cookie)
    with open("cookie.txt","w",encoding="utf-8") as f:
        f.write(json.dumps(cookie))





def main():
    getCookies()


if __name__ == '__main__':
    main()